/*
 * @Author: lduoduo
 * @Date: 2021-04-12 18:02:03
 * @Last Modified by: lduoduo
 * @Last Modified time: 2021-04-23 17:02:43
 * 流程所有输入组件列表
 */
import React, { useState, useRef } from 'react';
import { Checkbox, Input } from 'antd';

import BaseModal from '~/components/BaseModal';

import FormSelect from './components/FormSelect';
import FormAuth from './components/FormAuth';

const { TextArea } = Input;

export const InputFormSelect = {
  title: '引用表单',
  name: 'formDefinition',
  Comp: (e) => {
    const { value, onChange } = e;

    const open = () => {
      BaseModal.open({
        title: '表单选择',
        footer: null,
        className: 'modal-process-form-select',
        width: 900,
        content: <FormSelect value={value} onChange={onChange} />,
      });
    };

    return (
      <div className="ant-input select" onClick={open}>
        {(value && value.name) || '请选择'}
      </div>
    );
  },
};

export const InputFormAuth = {
  title: '表单权限',
  name: 'formAuth',
  Comp: FormAuth,
};

export const InputCode = {
  title: '节点code',
  name: 'id',
};

export const InputName = {
  title: '节点名称',
  name: 'name',
};

export const InputDesc = {
  title: '节点描述',
  name: 'documentation',
  Comp: TextArea,
};

export const InputAssignee = {
  title: '设置审批人',
  name: 'assignee',
  Comp: (e) => {
    const { value, onChange } = e;

    const onOpen = () => {
      BaseModal.open({
        title: '设置审批人',
        content: <div>demo</div>,
      });
    };

    return (
      <div className="ant-input" onClick={onOpen}>
        {value ? '已设置' : '请设置'}
      </div>
    );
  },
};

export const InputDefaultCondition = {
  title: '是否为默认路径',
  name: 'isDefaultFlow',
  Comp: (e) => {
    const { value, onChange: propsChange } = e;
    const onChange = (d) => propsChange(!value);

    return <Checkbox {...e} checked={value} onChange={onChange} />;
  },
};

export const InputSkipExpression = {
  title: '跳过表达式',
  name: 'skipExpression',
};

export const InputConditionExpression = {
  title: '条件表达式',
  name: 'conditionExpression',
};

export const InputSingleCheck = {
  title: '邮件提醒',
  name: 'emailNotify',
  Comp: (e) => {
    const { value, onChange: propsChange } = e;

    const onChange = (d) => propsChange(!value);

    return <Checkbox {...e} checked={value} onChange={onChange} />;
  },
};
